const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('sp_order', {
    order_id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true,
      comment: "主键id"
    },
    user_id: {
      type: DataTypes.MEDIUMINT.UNSIGNED,
      allowNull: false,
      comment: "下订单会员id"
    },
    order_number: {
      type: DataTypes.STRING(32),
      allowNull: false,
      comment: "订单编号",
      unique: "order_number"
    },
    order_price: {
      type: DataTypes.DECIMAL(10,2),
      allowNull: false,
      defaultValue: 0.00,
      comment: "订单总金额"
    },
    order_pay: {
      type: DataTypes.ENUM('0','1','2','3'),
      allowNull: false,
      defaultValue: "1",
      comment: "支付方式  0未支付 1支付宝  2微信  3银行卡"
    },
    is_send: {
      type: DataTypes.ENUM('是','否'),
      allowNull: false,
      defaultValue: "否",
      comment: "订单是否已经发货"
    },
    trade_no: {
      type: DataTypes.STRING(32),
      allowNull: false,
      defaultValue: "",
      comment: "支付宝交易流水号码"
    },
    order_fapiao_title: {
      type: DataTypes.ENUM('个人','公司'),
      allowNull: false,
      defaultValue: "个人",
      comment: "发票抬头 个人 公司"
    },
    order_fapiao_company: {
      type: DataTypes.STRING(32),
      allowNull: false,
      defaultValue: "",
      comment: "公司名称"
    },
    order_fapiao_content: {
      type: DataTypes.STRING(32),
      allowNull: false,
      defaultValue: "",
      comment: "发票内容"
    },
    consignee_addr: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "consignee收货人地址"
    },
    pay_status: {
      type: DataTypes.ENUM('0','1'),
      allowNull: false,
      defaultValue: "0",
      comment: "订单状态： 0未付款、1已付款"
    },
    create_time: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      comment: "记录生成时间"
    },
    update_time: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      comment: "记录修改时间"
    }
  }, {
    sequelize,
    tableName: 'sp_order',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "order_id" },
        ]
      },
      {
        name: "order_number",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "order_number" },
        ]
      },
      {
        name: "add_time",
        using: "BTREE",
        fields: [
          { name: "create_time" },
        ]
      },
    ]
  });
};
